<template>
	<view :style="viewColor">
		<view class="nav">
			<view class="nav-item" :class="nav_use == 1 ? 'nav-item-active' : ''" @click="clickNavUse(1)">订单推送</view>
			<view class="nav-item" :class="nav_use == 2 ? 'nav-item-active' : ''" @click="clickNavUse(2)">我的接单</view>
		</view>
		<view class="body">
			<block v-if="list.length">
				<demand :list="list" :isCreateTime="true" :isDemandPush="nav_use == 1" @delCommunity="delCommunity" @demandPushTop="demandPushTop"></demand>
			</block>
			<emptyPage v-else title="暂无数据"></emptyPage>
		</view>
		<authorize @onLoadFun="onLoadFun" :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse"></authorize>
	</view>
</template>

<script>
	let app = getApp();
	import {
		getUserCommunityList
	} from '@/api/community.js';
	import {
		recommendCommunity
	} from '@/api/circle.js';
	import {
		mapGetters
	} from "vuex";
	import authorize from '@/components/Authorize';
	import demand from '@/components/demand';
	import emptyPage from '@/components/emptyPage.vue';
	import { configMap } from '@/utils';
	import { HTTP_REQUEST_URL } from '@/config/app';
	import { getUserInfo } from '@/api/user.js';
	export default {
		components: {
			authorize,
			demand,
			emptyPage
		},
		data() {
			return {
				domain: HTTP_REQUEST_URL,
				loading: false,
				isAuto: false, //没有授权的不会自动授权
				isShowAuth: false ,//是否隐藏授权
				page: 1,
				isLoading: true,
				list: [],
				nav_use: 1,
			};
		},
		computed: configMap(['hide_mer_status'], mapGetters(['isLogin','viewColor','keyColor'])),
		onLoad(options) {
			if (this.isLogin) {
				this.recommendCommunity();
			} else {
                this.isAuto = true;
                this.isShowAuth = true
			}
		},
		mounted: function() {
		},
		methods: {
			clickNavUse(type) {
				this.isLoading = true;
				this.page = 1;
				this.list = [];
				this.nav_use = type;
				this.recommendCommunity();
			},
			recommendCommunity() {
				let that = this;
				if(!that.isLoading) return false;
				let params = {
					page: that.page,
					limit: 10,
					is_type: 3,
				}
				if (that.nav_use == 1) {
					params.is_demand_push = 1;
				} else {
					params.is_my_order_taking = 1;
				}
				recommendCommunity(params).then(res=>{
					that.list = that.list.concat(res.data.list);
					that.page++;
					that.isLoading = res.data.list.length >= 10;
				}).catch(err=>{
					
				})
			},
			// 推荐行业需求
			/* getUserCommunityList() {
				let that = this;
				if(!that.isLoading) return false;
				let data = {
					page: that.page, 
					limit: 10,
					type: 1,
				}
				getUserCommunityList(data).then(res=>{
					if(res.status == 200) {
						that.list = that.list.concat(res.data.list);
						that.page++;
						that.isLoading = res.data.list.length >= 10;
					}
				}).catch(err=>{
					console.log('getRecommendCustomerr', err);
				})
			}, */
			/**
			 * 授权回调
			 */
			onLoadFun: function() {
				this.isShowAuth = false;
				return uni.switchTab({
					url: '/pages/user/index'
				});
			},
			// 授权关闭
			authColse: function(e) {
				this.isShowAuth = e
			},
			// 删除内容
			delCommunity(index) {
				let that = this;
				that.list.splice(index, 1);
			},
			// 修改推荐
			demandPushTop(e) {
				let list = this.list;
				list[e.index].is_demand_push_top = e.is_demand_push_top;
				this.$set(this, 'list', list);
			}
		},
		onReachBottom() {
			this.recommendCommunity();
		}
	}
</script>

<style scoped lang="scss">
.body {
	padding: 0 30rpx;
}
.nav {
	display: flex;
	align-items: center;
	background-color: #fff;
	padding: 30rpx 0;
	.nav-item {
		flex: 1;
		font-size: 36rpx;
		font-weight: bold;
		color: #ccc;
		text-align: center;
	}
	.nav-item:last-child {
		border-left: 1rpx solid #000;
	}
	.nav-item-active {
		color: #000;
	}
}
</style>
